
package com.android.fitnesscenter.utils;

import android.widget.Toast;

public class ToastHelper {
    private static Toast sToast;
    private static ToastHelper sToastHelper;
    private static final byte[] LOCK = new byte[0];

    private ToastHelper() {

    }

    public static ToastHelper getInstance() {
        if (sToastHelper == null) {
            synchronized (LOCK) {
                if (sToastHelper == null) {
                    sToastHelper = new ToastHelper();
                }
            }
        }
        return sToastHelper;
    }

    /**
     * Using Toast way pop-up messages (display 3 seconds)
     * 
     * @Title: showLongMsg
     * @param msg
     */
    public void showLongMsg(String msg) {
        cancel();
        sToast = Toast.makeText(MainApplication.getAppContext(), msg,
                Toast.LENGTH_LONG);
        sToast.show();
    }

    /**
     * Using Toast way pop-up messages (display 2 seconds)
     * 
     * @Title: showShortMsg
     * @param msg
     */
    public void showShortMsg(String msg) {
        cancel();
        sToast = Toast.makeText(MainApplication.getAppContext(), msg,
                Toast.LENGTH_SHORT);
        sToast.show();
    }

    /**
     * @see {@link android.widget.Toast#cancel()}
     */
    public void cancel() {
        if (sToast != null) {
            sToast.cancel();
            sToast = null;
        }
    }

}
